<?php
	/**
	 * Elgg event category - add entry page
	 * 
	 * @package Elgg EventsManager
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author ProduceHere
	 * @copyright 
	 * @link 
 	**/

	// Load Elgg engine
       
		//require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
		gatekeeper();
		global $CONFIG;
		if(!isadminloggedin()){
			forward("pg/event_manager/" . $_SESSION['user']->username);
		}
		
	// Get the current page's owner
		$page_owner = page_owner_entity();
		if ($page_owner === false || is_null($page_owner)) {
			$page_owner = $_SESSION['user'];
			set_page_owner($_SESSION['guid']);
		}
		$container_guid = page_owner();
	//set the title
               	$title_text = elgg_echo("event_manager:newCatEve:title");
		$area2 = elgg_view_title($title_text);
//		$area2 = elgg_view_title(elgg_echo('stores:addcate'));
 
	// Get the form
//		$area2 .= "<div class=\"contentWrapper\">".elgg_view("event_manager/forms/edit_category")."</div>";
//		$area2 .= "<div class=\"contentWrapper\">".elgg_view("event_manager/forms/event/newCatEve")."</div>";

                //	$form = elgg_view("event_manager/forms/event/edit", array("entity" => $event));
	
                $area2 .= elgg_view("event_manager/forms/event/newCatEve");
                $area2 = elgg_view('page_elements/contentwrapper', array('body' => $area2));
   
	// These for left side menu
		$area1 .= gettags();
		
	// Get the body
		$body = elgg_view_layout("two_column_left_sidebar", $area1, $area2);	
			
	// Display page
		page_draw(elgg_echo('event_manager:newCatEve'),$body);
   //page_draw(elgg_echo('stores:addcate'),$body);

              
                
/**                
        gatekeeper();
                
	$title_text = elgg_echo("event_manager:newCatEve:title");
	
	$guid = get_input("guid");
	
	if(!empty($guid) && ($entity = get_entity($guid)))
	{	
		if($entity->getSubtype() == Event::SUBTYPE)
		{
			$event = $entity;
			$back_text = '<div class="event_manager_back"><a href="'.$event->getURL().'">'.elgg_echo('event_manager:title:backtoevent').'</a></div>';
			
			set_page_owner($event->container_guid);
		}
	}
	else 
	{
		$forward = true;
		$page_owner = page_owner_entity();
		
		if($page_owner && ($page_owner instanceof ElggGroup)){
			$who_create_group_events = get_plugin_setting('who_create_group_events', 'event_manager'); // group_admin, members
			
			if(!empty($who_create_group_events)){
				if((($who_create_group_events == "group_admin") && $page_owner->canEdit()) || (($who_create_group_events == "members") && $page_owner->isMember($user))){
					$forward = false;  	
				} 
			} 
			
		} else {
			$who_create_site_events = get_plugin_setting('who_create_site_events', 'event_manager');
			if(($who_create_site_events != 'admin_only') || isadminloggedin()){
				$forward = false;
			}
			set_page_owner(get_loggedin_userid());
		}
		if($forward){
			forward(EVENT_MANAGER_BASEURL);
		}
	}
	
	$form = elgg_view("event_manager/forms/event/edit", array("entity" => $event));

	$title = elgg_view_title($title_text . $back_text);
	
	$page_data = $title . $form;
	
	$body = elgg_view_layout("two_column_left_sidebar", "", $page_data);
	
	page_draw($title_text, $body);

                
		
?> 
**/